<?xml version="1.0" encoding="${encode}" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="${basePackage}.${moduleName}.dao.${className}Mapper" >
	<resultMap id="${className}ResultMap" type="${basePackage}.${moduleName}.model.${className}" >
		 <#list fields as field>
       		<result property="${field.name}"    column="${field.originalName}" jdbcType="${field.jdbcType}" />
       	 </#list>
	</resultMap>
    <sql id="${className}ColumnList" >
    	<#list fields as field>
    		${field.originalName}<#if field_has_next>,</#if>
       	 </#list>
    </sql>
    <select id="search${className}" resultMap="${className}ResultMap" parameterType="HashMap">
    	select  * from ${tableName}
		where 1=1
		<#list fields as field>
    		<if test="${field.name} !=null and ${field.name} != '' ">
		    	and ${field.originalName} = ${"#{" + field.name +",jdbcType="+ field.jdbcType +"}"}
			</if>
       	 </#list>
  	</select> 
  	
  	<select id="searchAll" resultMap="${className}ResultMap" parameterType="HashMap">
    	select * from ${tableName} 
  	</select> 
  	
  	<insert id="insert" parameterType="${basePackage}.${moduleName}.model.${className}">
  		INSERT INTO ${tableName} (
  			<#list fields as field>
    			${field.originalName}<#if field_has_next>,</#if>
       	 	</#list>
  		)VALUES (
  		<#list fields as field>
    		${"#{" + field.name +",jdbcType="+ field.jdbcType +"}"}<#if field_has_next>,</#if>
       	 </#list>
  		)
  	</insert>
  	
  	<insert id="update" parameterType="${basePackage}.${moduleName}.model.${className}">
  		update ${tableName}
		<trim prefix="set" suffixOverrides=",">
			<#list fields as field>
				<#if field_index != 0>
					<if test="${field.name} !=null and ${field.name} != '' ">
						${field.originalName} = ${"#{" + field.name +"}"} ,
					</if>
				</#if>
			</#list>
		</trim>
  		where ${fields[0].originalName} = ${"#{" + fields[0].name +"}"}
  	</insert>
  	
  	<delete id="delete" parameterType="String">
  		delete from ${tableName} where ${fields[0].originalName} = ${"#{" + fields[0].name +",jdbcType="+ fields[0].jdbcType +"}"}
  	</delete>
  	
  	<select id="get${className}" resultMap="${className}ResultMap" parameterType="String">
  		select * from ${tableName}  where ${fields[0].originalName} = ${"#{" + fields[0].name +",jdbcType="+ fields[0].jdbcType +"}"}
  	</select>
</mapper>